home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / arc.zoo / arccvt.c < prev    next >
C/C++ Source or Header  |  1989-01-29  |  3KB  |  123 lines

  1. /*
  2.  * $Header: arccvt.c,v 1.5 88/06/01 19:17:40 hyc Locked $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCCVT
  7.  * 
  8.  * Version 1.16, created on 02/03/86 at 22:53:02
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains the routines used to convert archives to use
  15.  * newer file storage methods.
  16.  * 
  17.  * Language: Computer Innovations Optimizing C86
  18.  */
  19. #include <stdio.h>
  20. #include "arc.h"
  21.  
  22. void    openarc(), rempath(), closearc(), abort(), pack(), writehdr(), filecopy();
  23. int    match(), readhdr(), unpack(), unlink();
  24.  
  25. static char     tempname[STRLEN];    /* temp file name */
  26.  
  27. void
  28. cvtarc(num, arg)        /* convert archive */
  29.     int             num;    /* number of arguments */
  30.     char           *arg[];    /* pointers to arguments */
  31. {
  32.     struct heads    hdr;    /* file header */
  33.     int             cvt;    /* true to convert current file */
  34.     int             did[MAXARG];/* true when argument was used */
  35.     int             n;    /* index */
  36.     char           *makefnam();    /* filename fixer */
  37. #ifndef __STDC__
  38.     FILE           *fopen();/* file opener */
  39. #endif
  40.     void            cvtfile();
  41.  
  42.     if (arctemp)        /* use temp area if specified */
  43.         sprintf(tempname, "%s.CVT", arctemp);
  44.     else
  45.         makefnam("$ARCTEMP.CVT", arcname, tempname);
  46. #if    !DOS
  47.     image = 1;
  48. #endif
  49.  
  50.     openarc(1);        /* open archive for changes */
  51.  
  52.     for (n = 0; n < num; n++)    /* for each argument */
  53.         did[n] = 0;    /* reset usage flag */
  54.     rempath(num, arg);    /* strip off paths */
  55.  
  56.     if (num) {        /* if files were named */
  57.         while (readhdr(&hdr, arc)) {    /* while more files to check */
  58.             cvt = 0;/* reset convert flag */
  59.             for (n = 0; n < num; n++) {    /* for each template
  60.                              * given */
  61.                 if (match(hdr.name, arg[n])) {
  62.                     cvt = 1;    /* turn on convert flag */
  63.                     did[n] = 1;    /* turn on usage flag */
  64.                     break;    /* stop looking */
  65.                 }
  66.             }
  67.  
  68.             if (cvt)/* if converting this one */
  69.                 cvtfile(&hdr);    /* then do it */
  70.             else {    /* else just copy it */
  71.                 writehdr(&hdr, new);
  72.                 filecopy(arc, new, hdr.size);
  73.             }
  74.         }
  75.     } else
  76.         while (readhdr(&hdr, arc))    /* else convert all files */
  77.             cvtfile(&hdr);
  78.  
  79.     hdrver = 0;        /* archive EOF type */
  80.     writehdr(&hdr, new);    /* write out our end marker */
  81.     closearc(1);        /* close archive after changes */
  82.  
  83.     if (note) {
  84.         for (n = 0; n < num; n++) {    /* report unused args */
  85.             if (!did[n]) {
  86.                 printf("File not found: %s\n", arg[n]);
  87.                 nerrs++;
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93. void
  94. cvtfile(hdr)            /* convert a file */
  95.     struct heads   *hdr;    /* pointer to header data */
  96. {
  97.     long            starts, ftell();    /* where the file goes */
  98.     FILE           *tmp, *fopen();    /* temporary file */
  99.  
  100.     if (!(tmp = fopen(tempname, "w+b")))
  101.         abort("Unable to create temporary file %s", tempname);
  102.  
  103.     if (note) {
  104.         printf("Converting file: %-12s   reading, ", hdr->name);
  105.         fflush(stdout);
  106.     }
  107.     unpack(arc, tmp, hdr);    /* unpack the entry */
  108.     fseek(tmp, 0L, 0);    /* reset temp for reading */
  109.  
  110.     starts = ftell(new);    /* note where header goes */
  111.     hdrver = ARCVER;        /* anything but end marker */
  112.     writehdr(hdr, new);    /* write out header skeleton */
  113.     pack(tmp, new, hdr);    /* pack file into archive */
  114.     fseek(new, starts, 0);    /* move back to header skeleton */
  115.     writehdr(hdr, new);    /* write out real header */
  116.     fseek(new, hdr->size, 1);    /* skip over data to next header */
  117.     fclose(tmp);        /* all done with the file */
  118.     if (unlink(tempname) && warn) {
  119.         printf("Cannot unsave %s\n", tempname);
  120.         nerrs++;
  121.     }
  122. }
  123.